package com.edu.framework.websocket.message;

import cn.hutool.crypto.digest.MD5;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.edu.common.utils.sign.Md5Utils;
import com.edu.framework.websocket.message.base.Response;
import com.edu.framework.websocket.message.card.CardInfoVO;
import com.edu.framework.websocket.message.card.TapCardRequest;
import com.edu.framework.websocket.message.card.TapVO;
import com.edu.framework.websocket.message.info.InfoRequest;
import com.edu.framework.websocket.message.terminal.TerminalRequest;
import com.edu.framework.websocket.message.terminal.TerminalVO;
import com.edu.framework.websocket.message.volume.VolumeRequest;
import com.edu.framework.websocket.message.weather.Coordinate;
import com.edu.framework.websocket.message.weather.WeatherRequest;

import java.math.BigInteger;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

public class Test {

    static {
        System.err.println("static block !");
    }
    public static void main(String[] args) {
//        String str = "\u00022BDB184C\r\n\u0003";
//
//        byte[] bytes = str.getBytes(Charset.defaultCharset());
//        int length = bytes.length;
//        Test test = new Test();
//        testMD5();
        testTapCardRequest();

    }



    public static void testMD5(){
        System.err.println(MD5.create().digestHex16("aaa"));
    }

    public static void testHex() {
        String hexString = "2BDB184C";
        StringBuffer buffer = new StringBuffer();
        for(int i=0;i<hexString.length();i=i+2){
            Integer i1 = Integer.valueOf(hexString.substring(i, i + 2),16);
            buffer.append(i1);
        }
        System.err.println(buffer.toString());
    }

    public static void testTapCardRequest(){
        TapVO tapVO = new TapVO();
        tapVO.setCanteenId("canteen202401");
        tapVO.setCardId("s11020240121");
        tapVO.setFee("10");
        tapVO.setChargeTime(System.currentTimeMillis());
        TapCardRequest request = new TapCardRequest();
        request.getData().put(TapCardRequest.RESP_KEY,tapVO);
        System.err.println(JSONObject.toJSONString(request));
        CardInfoVO vo = new CardInfoVO();
        vo.setBalance(10000f);
        vo.setClassName("高一二班");
        vo.setName("贺强");
        Response<CardInfoVO> response = Response.ok(TapCardRequest.TYPE, TapCardRequest.RESP_KEY,vo);
        System.err.println(JSONObject.toJSONString(response));
        vo.setFailedMessage("余额不足");
        vo.setBalance(5f);
        Response<CardInfoVO> response1 = Response.ok(TapCardRequest.TYPE, TapCardRequest.RESP_KEY,vo);

        System.err.println(JSONObject.toJSONString(response1));
    }


    public static void testVolumeRequest(){
        Response<String> response = Response.ok(VolumeRequest.TYPE, VolumeRequest.RESP_KEY,String.valueOf(66));
        System.err.println(JSONObject.toJSONString(response));
    }
    private static void testDe(){
        String weather = "{\"aqi\":\"空气质量 102\",\"conditionId\":\"0\",\"temp\":\"晴 -5~7 ℃\"}";

        Response<JSONObject> response = Response.ok(WeatherRequest.TYPE, WeatherRequest.RESP_KEY, JSONObject.parseObject(weather));
        System.err.println(JSONObject.toJSONString(response));
    }

    private static void testTerminal(){
        TerminalRequest request2 = new TerminalRequest();
        TerminalVO info = new TerminalVO();
        info.setCode("9527");
        request2.getData().put("info",info);
        System.err.println(JSONObject.toJSONString(request2));
    }

    private static void testWeatherRequest(){
        WeatherRequest request = new WeatherRequest();
        request.getData().put("coordinate", Coordinate.defaultCoordinate());
//        {"data":{"coordinate":{"lat":"39.94358","lon":"116.421393"}},"type":"WS_WEATHER"}
        System.err.println(JSONObject.toJSONString(request));
//        WeatherRequest request1 = JSONObject.parseObject(JSONObject.toJSONString(request), WeatherRequest.class);
//
//        System.err.println(JSONObject.toJSONString(request1));


//        String str = "{\"code\":0,\"data\":{\"city\":{\"cityId\":284609,\"counname\":\"中国\",\"ianatimezone\":\"Asia/Shanghai\",\"name\":\"东城区\",\"pname\":\"北京市\",\"secondaryname\":\"北京市\",\"timezone\":\"8\"},\"condition\":{\"condition\":\"多云\",\"humidity\":\"29\",\"icon\":\"1\",\"temp\":\"-2\",\"updatetime\":\"2023-12-2311: 40: 08\",\"vis\":\"20600\",\"windDegrees\":\"0\",\"windDir\":\"北风\",\"windLevel\":\"3\"}},\"msg\":\"success\",\"rc\":{\"c\":0,\"p\":\"success\"}}";
//        JSONObject jsonObject = JSONObject.parseObject(str);
//        WeatherResponse response = WeatherResponse.ok(jsonObject);
//        {"data":{"weather":{"code":0,"data":{"city":{"cityId":284609,"counname":"中国","ianatimezone":"Asia/Shanghai","name":"东城区","pname":"北京市","secondaryname":"北京市","timezone":"8"},"condition":{"condition":"多云","humidity":"29","icon":"1","temp":"-2","updatetime":"2023-12-2311: 40: 08","vis":"20600","windDegrees":"0","windDir":"北风","windLevel":"3"}},"msg":"success","rc":{"c":0,"p":"success"}}},"errmsg":"success","errno":0,"type":"WS_WEATHER"}
//        System.err.println(JSONObject.toJSONString(response));
    }

    private static void testInfoRequest(){
        InfoRequest request = new InfoRequest();
        request.addData("type","食堂");
        System.err.println(JSONObject.toJSONString(request));
    }



}
